package com.zhuoshi.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

import com.zhuoshi.bean.PaymentDetailBean;
import com.zhuoshi.utils.DbHelper;

/**
 * 回款明细数据层
 * @author Administrator
 *
 */
public class PaymentDetailDao {
	/**
	 * 通过合同数字编号 获取回款明细
	 * @param numerical
	 * @return
	 */
	public List<PaymentDetailBean> getList(int numerical){
		Connection conn = null;
		PreparedStatement pstat = null;
		ResultSet rs = null;
		List<PaymentDetailBean> list = new ArrayList<PaymentDetailBean>();
		try {
			conn = DbHelper.getConnection();
			StringBuffer sql = new StringBuffer();
			sql.append("select p.id as id,p.numerical as numerical,p.paydate as paydate,p.paymoney as paymoney,c.managerid as managerid,c.customerid as customerid,cu.custname as custname ");
			sql.append("from payment p,contractmaster c,customer cu ");
			sql.append("where p.numerical=c.numerical and c.customerid=cu.id and p.numerical=?");
			pstat = conn.prepareStatement(sql.toString());
			pstat.setInt(1, numerical);
			rs = pstat.executeQuery();
			while(rs.next()){
				PaymentDetailBean bean = new PaymentDetailBean();
				bean.setId(rs.getInt("id"));
				bean.setNumerical(rs.getInt("numerical"));
				bean.setPaydate(rs.getDate("paydate"));
				bean.setPaymoney(rs.getDouble("paymoney"));
				bean.setManagerid(rs.getInt("managerid"));
				bean.setCustomerid(rs.getInt("customerid"));
				bean.setCustname(rs.getString("custname"));
				list.add(bean);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}finally{
			DbHelper.dispose(conn, pstat, rs);
		}
		return list;
	}
}
